/* 数据统计接口 */
const express = require("express");
// 引入connect-multiparty中间件
var multipart = require("connect-multiparty");
// 创建中间件对象
var multipartMiddleware = multipart();
// 创建路由对象
const statistics = express.Router();
// 引入数据库配置
const db = require("../mysql");

statistics.get("/getData",multipartMiddleware, (req, res) => {
  const sqlStr = `select * from statistics`;
  db.query(sqlStr, (err, results) => {
    if (err) return res.json({ code: 400, message: err });
    res.json({ code: 200, data: results });
  });
})

statistics.get("/getDataByName/:username",multipartMiddleware, (req, res) => {
    console.log(req.params);
    const sqlStr = `select * from statistics where statistics_username ='${req.params.username}'`;
    db.query(sqlStr, (err, results) => {
      if (err) return res.json({ code: 400, message: err });
      res.json({ code: 200, data: results });
    });
  })

module.exports = statistics;
